<?php
/** Copyright 2014 TinPhp Systems, Inc.
 * @author zhangxilian 2013-8-15
 */
if (!defined('IN_TINPHP')) {
    exit('Access Denied');
}

require_once('indexApp.php');

/** 用户资料管理
 * @author ZhangXiLian 2014-09-12 */
class UserInfoController extends IndexAppController {
	
	private $userLogic;
	
	public function __construct() {
        parent::__construct();        
        $this->userLogic = new UserLogic();
	}
 	/** 会员中心用户资料 */
 	public function actionDefault(){
 		T::$tplFile = "user/index/userinfo";
 		
 		if($_POST['btnsubmit']){
 			$this->save();
 		}
 		
 		$userItem = $this->userLogic->getUserItem("*", "ID=?", array($this->user['ID']));
        $userItem['userType'] = $this->userLogic->getUserTypeItem("*", "ID=?",array($this->user['USERTYPE_ID']));
 		$userItem['info'] = $this->userLogic->getUserInfo("*", "ID=".$userItem['INFOID']);
        $userItem['info']['RELATIVE'] = $this->string2array($userItem['info']['RELATIVE']); 
        $userItem['info']['WORK'] = $this->string2array($userItem['info']['WORK']); 
 		$userItem['info']['ASSET'] = $this->string2array($userItem['info']['ASSET']); 

 		//初始变更
 		$idcart = $userItem['info']["IDCARD"];
 		if(!empty($idcart)){
 			$idcart_c = substr($idcart,4,strlen($idcart)-7);
 			$userItem['info']["IDCARD"] = str_replace($idcart_c,"**********",$idcart);
 		}
/* 		$email = $userItem['info']["EMAIL"];
 		if(!empty($email)){
 			$email_Arr = explode("@",$email);
 			$userItem['info']["EMAIL"]= str_replace($email_Arr[0],"******",$email);
 		}*/
/* 		$phone = $userItem["PHONE"];
 		if(!empty($phone)){
 			$phone_c = substr($phone,3,strlen($phone)-7);
 			$userItem["PHONE"] = str_replace($phone_c,"****",$phone);
 		}*/
 		
 		T::$tpl->set("userItem", $userItem);
 	}
 	/** 保存会员资料修改 */
 	public function save(){
 		
 		$dataArr = array();
 		$dataArr['GEO_CODE'] = RequestUtil::getPost('geo_code');
 		$dataArr['ADDRESS'] = RequestUtil::getPost('ADDRESS');
 		$dataArr['SEX'] = RequestUtil::getPost('SEX');
 		$dataArr['EMAIL'] = RequestUtil::getPost('EMAIL');
        $dataArr['QQ'] = RequestUtil::getPost('QQ');
        $dataArr['EDUCATION'] = RequestUtil::getPost('EDUCATION');
        $dataArr['BIRTHDAY'] = RequestUtil::getPost('BIRTHDAY');
        $dataArr['MARRY'] = RequestUtil::getPost('MARRY');
        $dataArr['HASCHILD'] = RequestUtil::getPost('HASCHILD');
        $dataArr['STATE'] = 1;

        $RELATIVE = array();
        $RELATIVE['NAME'] = RequestUtil::getPost('RELATIVE_NAME');
        $RELATIVE['SHIP'] = RequestUtil::getPost('RELATIVE_SHIP');
        $RELATIVE['TEL'] = RequestUtil::getPost('RELATIVE_TEL');
        $dataArr['RELATIVE'] = $this->array2string($RELATIVE,0);

        $WORK = array();
        $WORK['NAME'] = RequestUtil::getPost('WORK_NAME');
        $WORK['TYPE'] = RequestUtil::getPost('WORK_TYPE');
        $WORK['SIZE'] = RequestUtil::getPost('WORK_SIZE');
        $WORK['STATE'] = RequestUtil::getPost('WORK_STATE');
        $WORK['JOB'] = RequestUtil::getPost('WORK_JOB');
        $WORK['MONEY'] = RequestUtil::getPost('WORK_MONEY');
        $dataArr['WORK'] = $this->array2string($WORK);

        $ASSET = array();
        $ASSET['HOUSE'] = RequestUtil::getPost('HOUSE');
        $ASSET['HOUSE_DEAL'] = RequestUtil::getPost('HOUSE_DEAL');
        $ASSET['CAR'] = RequestUtil::getPost('CAR');
        $ASSET['CAR_DEAL'] =RequestUtil::getPost('CAR_DEAL');
        $ASSET['CAR_ID'] = RequestUtil::getPost('CAR_ID');
        $dataArr['ASSET'] = $this->array2string($ASSET);
 		$up = $this->userLogic->updateInfoVal($dataArr, "ID=?", array($this->user['INFOID']));

 		if($up){
 			T::$tpl->set("EndJS","$.jBox.tip('保存修改成功！', 'success');");
 		}else{
 			T::$tpl->set("EndJS","$.jBox.tip('保存失败请重试..', 'error');");
 		}
 	}
 	
 	/** 用户密码管理 */
 	public function actionPasswd(){
 		T::$tplFile = "user/index/userpasswd";
 		 		
 	}
 	
}//End CLass
?>
